define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    dragsort_url: '',
                    index_url: 'service/shop/shop/index' + location.search,

                    edit_url: 'service/shop/shop/edit',

                    multi_url: 'service/shop/shop/multi',
                    import_url: 'service/shop/shop/import',
                    table: 'service_shop'

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('商户信息'),operate: false,formatter:function (value,row){
                            return `<div style="display: flex">
        <img style="width: 100px;height: 100px;" src="${row.logo_image}"/>
        <div style="margin-left: 16px;">
            <div style=";display: flex;align-items: center;justify-content: space-between">
                <span  style="font-size: 16px;color: #333;">${row.name}</span>
                 <div style="background: rgba(248, 118, 121, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;color:rgba(248, 118, 121, 1);"><span style="color: rgba(248, 118, 121, 1)">ID：</span>${row.id}</div>
            </div>
            <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
            <span style="font-size: 14px;color: #999;margin-right: 20px;">简称：${row.abbr}</span>
                
            </div>
            <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
            <span>法人：</span>${row.username} &nbsp;&nbsp; ${row.mobile}
                <span style="margin-left:10px;">身份证：</span>${row.idcard}
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;">
                <div style="background: #FFF7E6;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">类型：</span>${row.type_text}</div>
                <div style="background: #F6F1FF;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">商家码：</span>${row.code}</div>
                <div style="background: rgba(22, 119, 255, 0.07);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;"><span style="color: #999999">证金：</span>￥${row.ensure_price}</div>
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;">
                <div style="background: rgba(240, 250, 243, 1);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;"><span style="color: #999999">统一社会信用代码：</span>${row.credit_code}</div>
            </div>
        </div>
    </div>`
                        }},
                        {field: 'id', title: __('接单信息'),operate: false,formatter:function (value,row){
                            return `
                            <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">每日可接单数量</span>
        <span style="color: #333;font-size: 14px;">${row.accept_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">已接单数量</span>
        <span style="color: #333;font-size: 14px;">${row.already_accept_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">商户订单收益分成%</span>
        <span style="color: #333;font-size: 14px;">${row.percent}</span>
    </div>
                            `
                        }},
                        {field: 'id', title: __('人员信息'),operate: false,formatter:function (value,row){
                            return `
                             <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">服务人员数量</span>
        <span style="color: #333;font-size: 14px;">${row.service_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">已拥有人员数量</span>
        <span style="color: #333;font-size: 14px;">${row.already_service_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height:  66px;">
        <span style="font-size: 14px;color: #999;">订单结算周期/天</span>
        <span style="color: #333;font-size: 14px;">${row.settle_day}</span>
    </div>
                            `
                        }},
                        {field: 'id', title: __('证件'),operate: false,formatter:function (value,row){
                            return `
                           <div style="display: flex;align-items: center;border-bottom: 1px solid #EEEEEE; padding: 10px 0;">
        <div style="display: flex;flex-direction: column;align-items: center;margin-right: 10px;">
            <img src="${row.front_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证正面</span>
        </div>
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.opposite_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证反面</span>
        </div>
    </div>
    <div style="display: flex;align-items: center;padding: 10px 0 0;">
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.license_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">营业执照</span>
        </div>
    </div>
                            `
                        }},
                        {field: 'id', title: __('经营分类'),operate: false,cellStyle: function () {return {css: {"min-width": "200px","max-width": "400px"}}},formatter:function (value,row){
                            let word = row.categoryname.split(',')
                            let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
                            for(let i=0; i < word.length; i++){
                                result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
                            }
                            result+='</div>'
                            return result
                        }},
                        {field: 'id', title: __('项目'),operate: false,cellStyle: function () {return {css: {"min-width": "300px","max-width": "500px","max-height": "20px"}}},formatter:function (value,row){
                            let word = row.goodsname.split(',')
                            let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
                            let sum_good = 6;
                            if(sum_good > word.length){
                                sum_good = word.length;
                            }
                            for(let i=0; i < sum_good; i++){
                                result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
                            }
                            result+='</div>'
                            return result
                        }},


                        {field: 'id', title: __('店铺信息'),operate: false, cellStyle: function () {return {css: {"min-width": "400px"}}},formatter:function (value,row){
                            return `
                           <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
        <div style="width: 90px;color: #999;text-align: left;">负责人姓名</div>
        <div>${row.leader_name}</div>
    </div>
    <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
        <div style="width: 90px;color: #999;text-align: left;">手机号</div>
        <div>${row.leader_mobile}</div>
    </div>
    <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: flex-start;">
        <div style="width: 90px;color: #999;text-align: left;flex-shrink: 0">营业时间</div>
        <p style="white-space: pre-line;text-align: left;">${row.trade_hour}</p>
    </div>
    <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: flex-start;">
        <div style="width: 90px;color: #999;text-align: left;flex-shrink: 0">地 址</div>
        <p style="white-space: pre-line;text-align: left;">${row.province}${row.city}${row.district}${row.address}</p>
    </div>

                            `
                        }},
                        {field: 'id', title: __('店铺简介'),operate: false, cellStyle: function () {return {css: {"min-width": "400px"}}},formatter:function (value,row){
                            return `
                           
    <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: flex-start;">
        
        <p style="white-space: pre-line;text-align: left;">${row.intro}</p>
    </div>
                            `
                        }},
                        {field: 'id', title: __('状态'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
                            return `
                           <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">开启到店</span>
        <span style="color: #62CB81;font-size: 14px;">${row.to_shop_text}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">权重</span>
        <span style="color: #333;font-size: 14px;">${row.weigh}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">状态</span>
        <span style="color: #1677FF;font-size: 14px;">${row.state_text}</span>
    </div>
                            `
                        }},
                        {field: 'id', title: __('时间'),operate: false, cellStyle: function () {return {css: {"min-width": "180px"}}},formatter:function (value,row){
                            return `
                           <div style="margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">创建时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.create_time}</div>
    </div>
    <div>
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">更新时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.update_time}</div>
    </div>
                            `
                        }},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'user_id', title: __('User_id'),visible: false},
                        {field: 'to_shop', title: __('To_shop'), searchList: {"0":__('To_shop 0'),"1":__('To_shop 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'ensure_price', title: __('Ensure_price'), operate:'BETWEEN',visible: false},
                        {field: 'accept_nums', title: __('Accept_nums'),visible: false},
                        {field: 'already_accept_nums', title: __('Already_accept_nums'),visible: false},
                        {field: 'service_nums', title: __('Service_nums'),visible: false},
                        {field: 'already_service_nums', title: __('Already_service_nums'),visible: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE',visible: false},
                        {field: 'abbr', title: __('Abbr'), operate: 'LIKE',visible: false},
                        {field: 'percent', title: __('Percent'),visible: false},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'code', title: __('Code'),visible: false},
                        {field: 'credit_code', title: __('Credit_code'), operate: 'LIKE',visible: false},
                        {field: 'license_image', title: __('License_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'username', title: __('Username'),visible: false},
                        {field: 'mobile', title: __('Mobile'),visible: false},
                        {field: 'idcard', title: __('Idcard'),visible: false},
                        {field: 'front_image', title: __('Front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'opposite_image', title: __('Opposite_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'intro', title: __('Intro'), operate: 'LIKE',visible: false},
                        {field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},

                        {field: 'categoryname', title: __('Category_name'),operate:false,visible: false},

                        {field: 'goodsname', title: __('Goods_name'),operate:false,visible: false},
                        {field: 'leader_name', title: __('Leader_name'),visible: false},
                        {field: 'leader_mobile', title: __('Leader_mobile'),visible: false},
                        {field: 'province', title: __('Province'), operate: 'LIKE',visible: false},
                        {field: 'city', title: __('City'), operate: 'LIKE',visible: false},
                        {field: 'district', title: __('District'), operate: 'LIKE',visible: false},
                        {field: 'address', title: __('Address'), operate: 'LIKE',visible: false},
                        {field: 'lng', title: __('Lng'),visible: false},
                        {field: 'lat', title: __('Lat'),visible: false},
                        {field: 'weigh', title: __('Weigh'), operate: false,visible: false},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'list',
                                    text: __('平台余额明细'),
                                    title: __('平台余额明细'),
                                    classname: 'btn btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/shopusermoneylog/index?user_id='+row.user_id;
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('保证金明细'),
                                    title: __('保证金明细'),
                                    classname: 'btn btn-xs btn-change btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/ensurelog/index?user_id='+row.user_id+'&type=1';
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('订单列表'),
                                    title: __('订单列表'),
                                    classname: 'btn btn-xs btn-list btn-success btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/order/order/index?shop_id='+row.id;
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('服务者列表'),
                                    title: __('服务者列表'),
                                    classname: 'btn btn-xs btn-list btn-danger btn-dialog',
                                    url: function(row){
                                        return 'service/skill/skill/index?shop_id='+row.id;
                                    },
                                },
                                {
                                    name: 'edit',
                                    text: __('编辑'),
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-status btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: 'service/shop/shop/edit',
                                }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'service/shop/shop/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},

                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'service/shop/shop/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'service/shop/shop/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
